package com.landary.parameterrplacement.utils;

import com.landary.parameterrplacement.webservice.UUMS_ServiceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.rmi.RemoteException;

/**
 * @author 刘欣
 * @createTime 2023/8/9 17:56
 * @description
 */
@Component
public class WebServiceClient {

    @Autowired
    private UUMS_ServiceProxy uums_serviceProxy;

    public String getDepts(String reqMsg) throws RemoteException {
        String req = reqMsgDept(reqMsg);
        String result = uums_serviceProxy.UUMS_SEND_GetSubDepartment_Service(req);
        return result;
    }

    public String getUsers(String appCodeName, String reqMsg) throws RemoteException {
        String req = reqMsgPerson(appCodeName, reqMsg);
        String result = uums_serviceProxy.UUMS_SEND_GetSubPerson_Service(req);
        return result;
    }

    private String reqMsgDept(String startDn) {
        StringBuilder requestXml = new StringBuilder();
        requestXml.append("<ReqMsg>")
                .append("<document>")
                .append("<![CDATA[")
                .append("<Info>")
                .append("<startDn>" + startDn + "</startDn>")
                .append("<scope>2</scope>")
                .append("</Info>")
                .append("]]>")
                .append("</document>")
                .append("</ReqMsg>");
        return requestXml.toString();
    }

    private String reqMsgPerson(String appCodeName, String startDn) {
        StringBuilder requestXml = new StringBuilder();
        requestXml.append("<ReqMsg>")
                .append("<document>")
                .append("<![CDATA[")
                .append("<Info>")
                .append("<appCodeName>" + appCodeName + "</appCodeName>")
                .append("<startDn>" + startDn + "</startDn>")
                .append("<scope>2</scope>")
                .append("</Info>")
                .append("]]>")
                .append("</document>")
                .append("</ReqMsg>");
        return requestXml.toString();
    }
}
